import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import { viewRoutes } from './view'

export const routes: RouteRecordRaw[] = [
  {
    name: 'login',
    path: '/login',
    component: () => import('@src/views/login/index.vue'),
  },
  {
    name: '404',
    path: '/404',
    component: () => import('@src/views/404/index.vue'),
  },
  {
    name: '/',
    path: '/',
    redirect: '/home',
    component: () => import('@src/components/Layout/index.vue'),
    children: [...viewRoutes],
  },
]
const router = createRouter({
  history: createWebHashHistory(),
  routes: routes,
})
router.beforeEach((to, from, next) => {
  if (to.matched.length === 0) {
    next('/404')
  }
 

  if (to.meta.role) {
    next()
  } else {
    next()
  }
})

export default router
